package org.faster.dal.descriptor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.faster.dal.utils.JsonUtils;

public class QueryResult implements Serializable {
    
    /**
     * 
     */
    private static final long serialVersionUID = 5675310807548144110L;
    
    private List<Map<String, Object>> resultList;
    
    private Map<String, Object> resultMap;

    public void setResultList(List<Map<String, Object>> resultList) {
        this.resultList = resultList;
    }

    public void setResultMap(Map<String, Object> resultMap) {
        this.resultMap = resultMap;
    }
    
    public Map<String, Object> get(){
        return resultMap;
    }
    
    public List<Map<String, Object>> getList(){
        return resultList;
    }
    
    public <T> T as(Class<T> beanClass){
        return JsonUtils.mapToObj(resultMap, beanClass);
    }
    
    public <T> List<T> asList(Class<T> beanClass){
        List<T> list = new ArrayList<T>();
        if(resultList != null){
            for (Object obj : resultList) {
                list.add(JsonUtils.mapToObj(resultMap, beanClass));
            }
        }
        return list;
    }
    
}
